package com.zhida.jiyangcenter.coupon

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import chooongg.base.annotation.ContentLayout
import chooongg.base.annotation.TitleBar
import com.zhida.jiyangcenter.R
import com.zhida.jiyangcenter.mian.BaseActivity
import com.zhida.jiyangcenter.mian.BaseFragment
import com.zhida.jiyangcenter.modle.fragment.MyCommentFragment
import kotlinx.android.synthetic.main.tablayout_viewpage.*

@TitleBar(false)
@ContentLayout(R.layout.tablayout_viewpage)
class CouponHistoryActivity : BaseActivity() {
    private lateinit var adapter: Adapter
    private val fragments = ArrayList<BaseFragment>()

    private class Adapter(fm: FragmentManager, val fragments: ArrayList<BaseFragment>) :
        FragmentPagerAdapter(fm) {
        override fun getItem(position: Int) = fragments[position]
        override fun getCount() = fragments.size
        override fun getPageTitle(position: Int) = fragments[position].getTitle()
    }

    override fun initConfig(savedInstanceState: Bundle?) {
        title_bar.navigationIcon(R.drawable.iv_back_fill) {
            finish()
        }.title("优惠券历史")
        fragments.add(CouponHistoryFragment(1).apply {
            setTitle("已使用")
        })
        fragments.add(CouponHistoryFragment(2).apply {
            setTitle("已过期")
        })

        adapter = Adapter(
            supportFragmentManager,
            fragments
        )
        view_pager.adapter = adapter
        view_pager.offscreenPageLimit = fragments.size - 1
        tab_layout.setupWithViewPager(view_pager)
    }
}